<HTML>
<HEAD>

<SCRIPT type="text/javascript" LANGUAGE="JavaScript">

function canAcceptCommand()
{
	var whatToDo = arguments[0];
	var whereToDo = arguments[1];

	if (dw.getDocumentDOM() == null && whatToDo != "about" && whatToDo != "settings" && whatToDo != "help" && whatToDo != "cloak" && whereToDo == "menu")
		return false;

	return true;
}

function receiveArguments()
{
	if (arguments.length != 2) return;

	var whatToDo = arguments[0];
	var whereToDo = arguments[1];
  
	var theHive= 'HKEY_LOCAL_MACHINE';
	var theKey = 'SOFTWARE\\TortoiseSVN';
	var theValueData='ProcPath';
  
	var apppath = MM.regGetValue(theHive, theKey, theValueData);
	
	if (whatToDo == "about" || whatToDo == "settings" || whatToDo == "help")
	{
		var args = '/command:' + whatToDo + ' /notempfile'
		MM.shellExecute(apppath, args, "");
	}
	
	else if (whatToDo == "cloak")
	{
		checkFolder(site.siteRelativeToLocalPath("/"));
		site.refresh("local");
	}
  
	else if (whereToDo == "site")
	{
		if (whatToDo == "add" || whatToDo == "remove" || whatToDo == "revert" || whatToDo == "ignore" || whatToDo == "lock" || whatToDo == "unlock" || whatToDo == "commit")
		{
			var args = '/command:' + whatToDo + ' /path:\"' + fileArrayToString(site.getSelection()) + '\" /notempfile'
			MM.shellExecute(apppath, args, "");
		}
		else
		{
			var args = '/command:' + whatToDo + ' /path:\"' + convertToPath(site.getSelection()[0]) + '\" /notempfile'
			MM.shellExecute(apppath, args, "");
		}
	
	}

	else if(whereToDo == "menu")
	{
		var args = '/command:' + whatToDo + ' /path:\"' + convertToPath(dw.getDocumentDOM().URL) + '\" /notempfile'
		MM.shellExecute(apppath, args, "");
	}
}

  function convertToPath(file)
  {
	var path = file.substring(8).replace("|",":");
	return path;

  }
  
  function fileArrayToString(files)
  {
	var fileString = convertToPath(files[0]);
  
	for(i = 1; i < files.length; i++)
	{
		fileString = fileString + '*' + convertToPath(files[i])
	}
	
	return fileString;
  
  }
  
  function checkFolder(folder)
  {
	var sel = DWfile.listFolder(folder, "directories");
	
	for( var i in sel )
	{
		var str = DWfile.getAttributes(folder + sel[i]);

	
		if(str && (str.indexOf("D") != -1))
		{
			if(sel[i] == ".svn" || sel[i] == "_svn")
			{
				site.cloak(folder + sel[i]);
			}
			else
			{
				checkFolder(folder + sel[i] + "\\");
			}
		}
	}
  }

</SCRIPT>

</HEAD>
<BODY>
</BODY>

</HTML>